USE [BMIG_Mensual_POST_CADENA]
GO

/****** Object:  StoredProcedure [dbo].[WASP_M0002_REFUNDIMIENTO]    Script Date: 11/24/2011 14:34:59 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[WASP_M0002_REFUNDIMIENTO]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[WASP_M0002_REFUNDIMIENTO]
GO

USE [BMIG_Mensual_POST_CADENA]
GO

/****** Object:  StoredProcedure [dbo].[WASP_M0002_REFUNDIMIENTO]    Script Date: 11/24/2011 14:34:59 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[WASP_M0002_REFUNDIMIENTO]
AS
BEGIN
	SELECT	aocta = fsh016.hcta
			,Z07391Op1 = fsh016.hoper 
			,Z07391su1 = fsh016.hsucur
			,Z07394IMP = fsh016.hcimp1
	INTO	as_refundidos
	FROM	fsh016
			,fsh015 
	WHERE	fsh016.hfcon=fsh015.hfcon
	AND		fsh016.hcmod=fsh015.hcmod 
	AND		fsh016.htran=fsh015.htran 
	AND		fsh016.hnrel=fsh015.hnrel 
	AND		fsh016.hsucor=fsh015.hsucor 
	AND		fsh016.hcmod in (30, 32) 
	AND		fsh016.hrubro = 1111003210 
	AND		fsh015.hccorr <> 99 
	AND 	fsh016.hcodmo = 2 
	AND		fsh016.hsubop <= 99
END

GO


